const os = require("os");

function getMemery(){
	let memory = process.memoryUsage();
	let format = function(bytes){
		return `${(bytes / 1024 / 1024).toFixed(2)}MB`;
	}

	let totalM = os.totalmem;
	let freeM = os.freemem;
	console.log(`totalM:${totalM}\tfreeM:${freeM}`);
	console.log(`heapTotal:${format(memory.heapTotal)}\theapUsed:${format(memory.heapUsed)}`);
}

let count = 0;
let useMem = () => {
	let size = 20 * 1024 * 1024;
	let arr = new Array(size);
	console.log(count ++);
	return arr;
}

let total = [];

let size = 20 * 1024 * 1024

function fn(){
	//
	let arr1 = new Array(size);
	let arr2 = new Array(size);
	let arr3 = new Array(size);
	let arr4 = new Array(size);
	let arr5 = new Array(size);
}

fn();

for(let i = 0; i < 60; i ++){
	getMemery();
	total.push(useMem());
}

console.log("success");